package com.kofigyan.stateprogressbarsample.not_stateprogressbar.custom;

import com.kofigyan.stateprogressbar.utils.AttrSetUtils;
import com.kofigyan.stateprogressbarsample.ResourceTable;
import ohos.agp.components.*;
import ohos.agp.components.element.Element;
import ohos.app.Context;

public class ContentHeaderView extends DirectionalLayout {

    private Text mHeaderTitle;
    private Image mHeaderImage;

    public ContentHeaderView(Context context) {
        this(context, null);
    }

    public ContentHeaderView(Context context, AttrSet attrSet) {
        this(context, attrSet, null);
    }

    public ContentHeaderView(Context context, AttrSet attrSet, String styleName) {
        super(context, attrSet, styleName);
        init(context, attrSet);
    }

    private void init(Context context, AttrSet attrSet) {
        LayoutScatter.getInstance(context)
                .parse(ResourceTable.Layout_view_content_header, this, true);

        mHeaderTitle = (Text) findComponentById(ResourceTable.Id_tvHeaderTitle);
        mHeaderImage = (Image) findComponentById(ResourceTable.Id_ivHeaderImage);

        if (attrSet != null) {
            final String headerTitle = AttrSetUtils.optString(attrSet, "headerTitle", "");
            final Element headerImage = AttrSetUtils.optElement(attrSet, "headerSrc", null);

            setHeaderTitle(headerTitle);
            setHeaderImage(headerImage);
        }
    }

    public void setHeaderTitle(String headerTitle) {
        this.mHeaderTitle.setText(headerTitle);
    }

    public void setHeaderImage(Element headerImage) {
        this.mHeaderImage.setImageElement(headerImage);
    }
}
